<?php

namespace api\wechat;

//政策文件类
class file
{
    //获取分页列表
    public function getList($data){
        $page=(int)$data['page'];
        $size=(int)$data['size'];
        $start=($page-1)*$size;

        $sql="select * from file where is_delete=1 and status=1 order by `id` DESC";
        $con=con();
        $data=mysqli_query($con,$sql." limit $start,$size");
        $data=mysqli_fetch_all($data,true);
        $total=mysqli_query($con,$sql);
        $total=mysqli_num_rows($total);
        mysqli_close($con);
        for($i=0;$i<count($data);$i++){
            if(empty($data[$i]['file'])){
                $data[$i]['file']=[];
            }else{
                $file=json_decode($data[$i]['file'],true);
                for($o=0;$o<count($file);$o++){
                    $file[$o]['size']=formatSize($file[$o]['size']);
                }
                $data[$i]['file']=$file;
            }
            $data[$i]['create_time']=date('Y-m-d',$data[$i]['create_time']);
        }
        return out_right([
            'data'=>$data,
            'page'=>$page,
            'size'=>$size,
            'total'=>$total,
            'total_page'=>ceil($total/$size),
        ]);
    }
}